import { BrowserHrm } from 'weaver-mobile-page';
import React from 'react';
import { inject, observer } from 'mobx-react';
import querystring from 'querystring';

@inject('browserHrmStore')
@observer
export default class BrowserHrmView extends React.Component {

  getRequest(key) {
    const url = decodeURI(window.location.href);
    let theRequest = {};

    if (url.indexOf("?") !== -1) {
      const str = url.split('?')[1];

      theRequest = querystring.parse(str, '&', '=');
    }
    return theRequest[key];
  }
 
  render () {
    const { browserHrmStore: { bStore } } = this.props;
    const isSingle = Boolean(Number(this.getRequest('isSingle')));
    const valueStr = this.getRequest('value');
    let values = valueStr ? JSON.parse(decodeURI(valueStr)) : [];
    const uuid = this.getRequest('uuid');
    
    return (
      <BrowserHrm
        store={bStore}
        hasAdvanceSerach
        isSingle={isSingle}
        type={1}
        valueArray={values}
        notGoBack={true}
        onSureOfRouteNumber={-1}
        clearToChangeRoute={false}
        onChange={(ids, names) => {
          window.parent.postMessage({ [uuid]: { ids, names }},'*')
        }}
      />
    );
  }
}